using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Web.Core.Objects;
using Web.Core;

public partial class AdminCP_AddEditAdvertisement : System.Web.UI.UserControl
{
    public int adsID = 0;
    public string header = "";
    string aDo = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        aDo = Request.Params["do"];
        if (aDo != null)
        {
            this.RequiredFieldValidatorImage.ErrorMessage = Resources.Lang.Require;
            this.RequiredFieldValidatorUrl.ErrorMessage = Resources.Lang.Require;

            if (Request.Params["aid"] != null)
                adsID = int.Parse(Request.Params["aid"]);
            switch (aDo)
            {
                case "edit":
                    header = Resources.Lang.Edit;
                    Advertisement ads = Advertisements.GetAdvertisementsByID(adsID);
                    this.txtImage.Text = ads.Image;
                    this.txtUrl.Text = ads.Url;
                    break;
                case "add":
                    header = Resources.Lang.Add;
                    break;
                default:
                    break;
            }
        }

    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string image = "", url = "";
        try
        {
            image = this.txtImage.Text;
        }
        catch { }
        try
        {
            url = this.txtUrl.Text;
        }
        catch { }
        if (aDo == "edit")
        {
            Advertisement ads = new Advertisement(adsID, image, url);
            Advertisements.UpdateAdvertisement(ads);            
        }
        else if (aDo == "add")
        {
            Advertisement ads = new Advertisement(adsID, image, url);
            Advertisements.InsertAdvertisement(ads);            
        }
        Response.Redirect("Advertisements.aspx");
    }
}
